package cn.tmpan.project.controller;

import cn.tmpan.project.common.ServerResponse;
import cn.tmpan.project.service.IJtcyxxService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import io.swagger.annotations.Api;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * <p>
 * 家庭成员电话 前端控制器
 * </p>
 *
 * @author AutoGenerator
 */
@Api(tags = {"Jtcyxx"}, description = "家庭成员电话模块")
@RestController
@RequestMapping(value = "/jtcyxx")
public class JtcyxxRestController {

    @Autowired
    private IJtcyxxService jtcyxxService;

    @ApiImplicitParams({
            @ApiImplicitParam(value = "家庭成员姓名", name = "jtcyxm", required = true),
            @ApiImplicitParam(value = "家庭成员身份证", name = "jtcysfz", required = true),
            @ApiImplicitParam(value = "家庭成员电话号码", name = "jtcydh", required = true),
            @ApiImplicitParam(value = "户主身份证号码", name = "sfzhm",required = true)
    })
    @ApiOperation(value = "新增家庭成员信息", response = ServerResponse.class)
    @PostMapping(value = "/insert")
    public ServerResponse insertJtcyxx(String jtcyxm, String jtcysfz, String jtcydh, String sfzhm) {
        try {
            return ServerResponse.createBySuccess(this.jtcyxxService.insertJtcyxx(jtcyxm, jtcysfz, jtcydh, sfzhm));
        } catch (Exception e) {
            return ServerResponse.createByErrorMessage(e.getMessage());
        }
    }

    @ApiImplicitParams({
            @ApiImplicitParam(value = "编码", name = "bm",required = true),
            @ApiImplicitParam(value = "家庭成员姓名", name = "jtcyxm", required = true),
            @ApiImplicitParam(value = "家庭成员身份证", name = "jtcysfz", required = true),
            @ApiImplicitParam(value = "家庭成员电话号码", name = "jtcydh", required = true)
    })
    @ApiOperation(value = "修改家庭成员信息", response = ServerResponse.class)
    @PutMapping(value = "/update")
    public ServerResponse updateJtcyxx(String bm, String jtcyxm, String jtcysfz, String jtcydh) {
        try {
            return ServerResponse.createBySuccess(this.jtcyxxService.updateJtcyxx(bm, jtcyxm, jtcysfz, jtcydh));
        } catch (Exception e) {
            return ServerResponse.createByErrorMessage(e.getMessage());
        }
    }

    @ApiImplicitParams({
            @ApiImplicitParam(value = "户主身份证号码", name = "sfzhm", required = true)
    })
    @ApiOperation(value = "根据户主身份证号码查询家庭成员", response = ServerResponse.class)
    @GetMapping(value = "/select/by/sfzhm")
    public ServerResponse selectJtcyxxBySfzhm(String sfzhm) {
        try {
            return ServerResponse.createBySuccess(this.jtcyxxService.selectJtcyxxBySfzhm(sfzhm));
        } catch (Exception e) {
            return ServerResponse.createByErrorMessage(e.getMessage());
        }
    }

    @ApiImplicitParams({
            @ApiImplicitParam(value = "编码", name = "bm", required = true)
    })
    @ApiOperation(value = "删除家庭成员信息", response = ServerResponse.class)
    @DeleteMapping(value = "/delete/by/bm")
    public ServerResponse deleteJtcyxx(String bm) {
        try {
            return ServerResponse.createBySuccess(this.jtcyxxService.deleteJtcyxx(bm));
        } catch (Exception e) {
            return ServerResponse.createByErrorMessage(e.getMessage());
        }
    }

    @GetMapping("/download")
    public void downloadExcel(HttpServletResponse  response, HttpServletRequest request){
        this.jtcyxxService.downloadExcel(response,request);
    }
}
